package trlygjj.tanruiliyigenjinjin.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.RecruitmentPlan;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.QueryObject;
import trlygjj.tanruiliyigenjinjin.service.IRecruitmentPlanService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("recruitmentPlan")
public class RecruitmentPlanController {

    @Autowired
    private IRecruitmentPlanService recruitmentPlanService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @RequestMapping("")
    public String index(){
        return "recruitmentPlan/list";
    }

    /**
     * 具有分页和高级查询
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
        PageResult result = recruitmentPlanService.query(qo);
        System.out.println(result+"Controller");
        return result;
    }

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("listAll")
    @ResponseBody
    public List<RecruitmentPlan> listAll(){
        return recruitmentPlanService.selectAll();
    }


    /**
     * 审核
     * @param recruitmentPlan 保存的计划对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(RecruitmentPlan recruitmentPlan){
        JsonResult result = new JsonResult();
        try{
            recruitmentPlanService.insert(recruitmentPlan);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }


}
